{{template "header" .}}
<title>分类 - 我的博客分类</title>
</head>
<body>
<div class="navbar navbar-default navbar-static-top bs-docs-nav">
    <div class="container">
    {{template "navbar" .}}
    </div>
</div>

<div class="container">
    <form class="form-horizontal" method="POST" action="">
        <input type="hidden" name="type" value="add">
        <div class="form-group">
            <label for="new_category" class="col-sm-2 control-label">分类:</label>
            <div class="col-sm-6">
                <input type="text" required class="form-control" id="new_category" name="new_category">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-6">
                <button type="submit" class="btn btn-default">添加</button>
            </div>
        </div>
    </form>

    <div class="panel panel-default">
        <div class="panel-heading">类别列表</div>
        <div class="panel-body">
            <p>...</p>
        </div>

        <!-- Table -->
        <table class="table">
            <thead>
            <th>#</th>
            <th>名字</th>
            <th>添加时间</th>
            <th>操作</th>
            </thead>
            <tbody>
            {{range .categoryList}}
            <tr>
                <td>{{.Id}}</td>
                <td>{{.Title}}</td>
                <td>{{.Created}}</td>
                <td><a onclick="delCate(this)" data-id="{{.Id}}">删除</a></td>
            </tr>
            {{end}}
            </tbody>
        </table>
    </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
    function delCate(el) {
        $.post("/category", {"id": $(el).data('id'), "type": 'del'},
                function (msg) {
                    alert(msg)
                    window.location.reload()
                });
    }
</script>
</html>